<?php

class Login extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if (!$this->Application->User->IsGuest)
			$this->Response->redirect($this->Service->ConstructUrl("Index"));

		if (!$this->IsPostBack)
		{
			$this->Master->pageHead->Title = $this->Application->Parameters["WEBSITE_TITLE"]." - Log in";
			$this->Master->cssMenuLogIn->Value = "current_menu_item";
			$this->Page->ClientScript->registerDefaultButton($this->mainPanel,$this->btnLogin);
		}
	}
	
	public function btnLogin_Clicked($sender, $param)
	{
		if ($this->IsValid)
		{
			$auth = $this->Application->getModule('auth');
			$mail = $this->txtLoginEmail->Text;
			$pass = $this->txtLoginPassword->Text;
			$sessionExpiredSeoncds = 0;
			
			/*if ($this->chkRemember->Checked)
				$sessionExpiredSeoncds = TPropertyValue::ensureInteger($this->Application->Parameters["USER_TIMEOUT"]);*/
			
			if ($auth->login($mail, $pass, $sessionExpiredSeoncds))
			{
				$url = $auth->ReturnUrl;				
				//if ($this->Application->User->Status == 0)
					//$url = $this->Service->ConstructUrl("ActivateAccount");
				if (empty($url))
					$url = $this->Service->ConstructUrl("Index");
				$this->Response->redirect($url);
			}
			else
			{
				$this->Notice->Type = UserNoticeType::Error;
				$this->Notice->Text = $this->Application->getModule('message')->translate('USER_LOGIN_FAILED');
				$this->txtLoginPassword->Text="";
				$this->txtLoginPassword->focus();
			}
		}		
	}
}

?>